﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RoleListCtrl.ascx.cs" Inherits="WebUI.Controls.RoleListCtrl" %>


<script type="text/javascript">
    var <%=ClientID %>clickOnCheckbox;
    var <%=ClientID %>selectedRow = null;       
    var <%=ClientID %>selectedCheckbox = null; 
    var <%=ClientID %>selectedID = null; 
    var <%=ClientID %>selectedClass = null; 
    
    function resetGridSelection<%=ClientID %>(){
        <%=ClientID %>selectedRow = null;   
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;          
        <%=ClientID %>selectedCheckbox = null; 
        <%=ClientID %>selectedID = null; 
        <%=ClientID %>selectedClass = null; 
    }
    
    function clickOnCheckBox<%=ClientID %>(cb){
        <%=ClientID %>clickOnCheckbox = true;
    }
    
    function onItemClick<%=ClientID %>(sender)
    {
        if(<%=ClientID %>clickOnCheckbox){
            <%=ClientID %>clickOnCheckbox = false;
            return;
        }
        
        if(<%=ClientID %>selectedRow != null){
            if(<%=ClientID %>selectedRow.className)
                <%=ClientID %>selectedRow.className = <%=ClientID %>selectedClass;
            else
                <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;
        }
        
        if(sender.className){
            <%=ClientID %>selectedClass = sender.className;
            sender.className = "CustomGridSelectedItem";
        }
        else{
            <%=ClientID %>selectedClass = sender.getAttribute("class");
            sender.setAttribute("class", "CustomGridSelectedItem");
        }
        <%=ClientID %>selectedRow = sender;
        
        var inputs = sender.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
                <%=ClientID %>selectedCheckbox = inputs[i];
                inputs[i].checked = true;
                break;
            }
        }
        
        <%=ClientID %>selectedID = <%=ClientID %>selectedRow.getAttribute("ItemID");
    }
    
    function selectAll<%=ClientID %>(cbAll){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].parentNode.getAttribute('RowHeader') == 1){
                inputs[i].checked = cbAll.checked;
            }
        }
    }
    
    function getSelectedItemID<%=ClientID %>()
    {
        return <%=ClientID %>selectedID;
    }
</script>

<%--start modify here--%>
<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None" class="customGrid"
    AutoGenerateColumns="false" EmptyDataText="No record to display" ItemStyle-Wrap="true" CellPadding="1" CellSpacing="1"
    OnSortCommand="grid_OnSortCommand" OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound"
    OnPageIndexChanged="grid_OnPageIndexChanged" AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
    <PagerStyle Mode="NumericPages" PageButtonCount="10"   />
    <Columns>
        <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
            <HeaderTemplate><asp:CheckBox ID="cbSelectAll" runat="server" /></HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' RowHeader='1' />
            </ItemTemplate>
        </asp:TemplateColumn>
        <%--start modify here--%>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px" DataField="ID" SortExpression="ID" HeaderText="Product ID" Visible="false"></asp:BoundColumn>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="250px" DataField="RoleName" SortExpression="RoleName" HeaderText="Name"></asp:BoundColumn>
        
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Products">
            <ItemTemplate>
                <asp:CheckBox ID="chkProducts" runat="server" Checked='<%# Eval("Products") %>' />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Sales">
            <ItemTemplate>
                <asp:CheckBox ID="chkSales" runat="server" Checked='<%# Eval("Sales") %>' />
            </ItemTemplate>
        </asp:TemplateColumn>

         <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Edit Sales">
            <ItemTemplate>
                <asp:CheckBox ID="chkEditSales" runat="server" Checked='<%# Eval("EditSales") %>' />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Contracts" Visible="false"> 
            <ItemTemplate>
                <asp:CheckBox ID="chkContracts" runat="server" Checked='<%# Eval("Contracts") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Purchase">
            <ItemTemplate>
                <asp:CheckBox ID="chkPurchase" runat="server" Checked='<%# Eval("Purchase") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Customers">
            <ItemTemplate>
                <asp:CheckBox ID="chkCustomers" runat="server" Checked='<%# Eval("Customers") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Suppliers">
            <ItemTemplate>
                <asp:CheckBox ID="chkSuppliers" runat="server" Checked='<%# Eval("Suppliers") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Repair" Visible="false">
            <ItemTemplate>
                <asp:CheckBox ID="chkRepair" runat="server" Checked='<%# Eval("Repair") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Report">
            <ItemTemplate>
                <asp:CheckBox ID="chkReport" runat="server" Checked='<%# Eval("Report") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

         <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Admin">
            <ItemTemplate>
                <asp:CheckBox ID="chkAdmin" runat="server" Checked='<%# Eval("Admin") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="System Admin">
            <ItemTemplate>
                <asp:CheckBox ID="chkSysAdmin" runat="server" Checked='<%# Eval("SystemAdmin") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>

         <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="Expense">
            <ItemTemplate>
                <asp:CheckBox ID="chkExpense" runat="server" Checked='<%# Eval("Expense") %>'  />
            </ItemTemplate>
        </asp:TemplateColumn>
        
        <%--end modify here--%>
    </Columns>
</asp:DataGrid>
<asp:HiddenField ID="hidSelectedID" runat="server" />